package org.softmed.rest.editor.comps.full;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;

import net.miginfocom.swing.MigLayout;

import org.softmed.rest.editor.EditorUtil;
import org.softmed.rest.editor.FilePathAware;
import org.softmed.rest.editor.FilePathProvider;
import org.softmed.rest.editor.commons.SwingUtil;
import org.softmed.rest.editor.commons.URIProvider;
import org.softmed.rest.editor.comps.HandlerEditor;
import org.softmed.rest.editor.comps.utils.DeletePanel;
import org.softmed.rest.editor.comps.utils.list.ListFieldPanel;
import org.softmed.rest.editor.comps.utils.list.showListFieldDetails;
import org.softmed.swing.IconManager;

public class HandlerEditorFull extends HandlerEditor implements getDeletePanel,
		showListFieldDetails {

	DeletePanel deletePanel = new DeletePanel(this);

	ListFieldPanel list = new ListFieldPanel("Parameters", "parameters",
			ParameterEditorFull.class, this, false);

	private FilePathProvider filePathProvider;

	int width = 566;

	public HandlerEditorFull(URIProvider uriProvider) throws Throwable {
		super(uriProvider);
		setup();
	}

	public void setup() {

		setFullBackground(new Color(197, 226, 223));

		// setFullBackground(Color.YELLOW);
//		 setBorder(BorderFactory.createLineBorder(Color.black));
		// setBackground(Color.yellow);
		active.setText("Active");
		SwingUtil.setMinSize(this, width, 20);
		// EditorUtil.smallestHeight);
		MigLayout layout = new MigLayout("left, insets "
				+ EditorUtil.smallestInsets + ", gap 0");
		setLayout(layout);

		JLabel title = new JLabel("Handler");
		title.setFont(SwingUtil.editorTitleFont);
		add(title, "w 65!");

		getFilePaths.setBorder(BorderFactory.createEtchedBorder());
//		getFilePaths.setBackground(Color.WHITE);

		add(id, "w 25!");
		add(active, "w 70!");
		add(new JLabel("Path"), "w 33!");
		add(getFilePaths, "w 20!, h 20!");
		add(path, "w 260!");
		add(maxMinPanel);
		add(deletePanel, "wrap");
		add(list, "span 10, wrap");

		minimize();

	}

	public void setFullBackground(Color color) {
		setBackground(color);
		list.setFullBackground(color);
		list.setChildrenEditorBackground(color);
		active.setBackground(color);
		deletePanel.setBackground(color);
		maxMinPanel.setBackground(color);
	}

	@Override
	public DeletePanel getDeletePanel() {
		return deletePanel;
	}

	public void setEntity(Object entity) throws Throwable {
		super.setEntity(entity);
		// list.setEntityRefresh();
	}

	@Override
	public void hideListFieldDetails() {
		list.hideListFieldDetails();

	}

	@Override
	public void showListFieldDetails() throws Throwable {
		list.showListFieldDetails();

	}

	@Override
	public void customMaximize() {

		list.setVisible(true);
		SwingUtil.setMinSize(this, width, 30);

		// TODO Auto-generated method stub
		try {
			list.showListFieldDetails();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public void customMinimize() {
		// TODO Auto-generated method stub

		list.setVisible(false);
		SwingUtil.setSize(this, width, 30);

	}

}
